package com.sy.simpleegg.ui.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.EditText
import androidx.lifecycle.lifecycleScope
import com.sy.simpleegg.R
import com.sy.simpleegg.base.BaseMvpFragment
import com.sy.simpleegg.config.Config
import com.sy.simpleegg.constant.Constant
import com.sy.simpleegg.constant.Languages
import com.sy.simpleegg.databinding.FragmentConfigBinding
import com.sy.simpleegg.event.RecBasicConfigEvent
import com.sy.simpleegg.event.RecCashConfigEvent
import com.sy.simpleegg.event.RecMotorConfigEvent
import com.sy.simpleegg.event.RefreshBasicConfigEvent
import com.sy.simpleegg.event.RefreshCashConfigEvent
import com.sy.simpleegg.event.RefreshMotorConfigEvent
import com.sy.simpleegg.event.SaveBasicConfigEvent
import com.sy.simpleegg.event.SaveCashConfigEvent
import com.sy.simpleegg.event.SaveMotorConfigEvent
import com.sy.simpleegg.ext.logFile
import com.sy.simpleegg.ext.onClick
import com.sy.simpleegg.ext.showToastMsg
import com.sy.simpleegg.mvp.contract.PackageManageContract
import com.sy.simpleegg.mvp.presenter.PackageManagePresenter
import com.sy.simpleegg.ui.layout.TouchLinearLayout
import com.sy.simpleegg.util.ByteUtil
import com.sy.simpleegg.util.CommonUtil
import com.sy.simpleegg.util.GsonUtil
import com.sy.simpleegg.util.MultiLanguageUtils
import com.sy.simpleegg.util.Preference
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class ConfigFragment :
    BaseMvpFragment<PackageManageContract.View, PackageManageContract.Presenter, FragmentConfigBinding>(),
    PackageManageContract.View {

    /**
     * 基础配置 lyy模板配置格式
     */
    private var basicConfigHex: String by Preference(Constant.SETTING_BASIC_CONFIG, "0000000000000000000000010001")
    /**
     * 现金配置 lyy模板配置格式
     */
    private var cashConfigHex: String by Preference(Constant.SETTING_CASH_CONFIG, "0000000000000000000000000000000000000000")
    /**
     * 马达配置 lyy模板配置格式
     */
    private var motorConfigHex: String by Preference(Constant.SETTING_MOTOR_CONFIG, "040214")
    /**
     * 国家地区
     */
    private var country: Int by Preference(Constant.SETTING_COUNTRY, Config.DEFAULT_COUNTRY_CODE)
    /**
     * 语言
     */
    private var language: Languages by Preference(Constant.SETTING_LANGUAGE_CONFIG, Languages.ZH)

    private var motorModeHex = ""
    private var motor1StateModeHex = ""
    private var motor2StateModeHex = ""
    private var dispenser1StateHex = ""
    private var dispenser1ProportionHex = ""
    private var dispenser2StateHex = ""
    private var dispenser2ProportionHex = ""
    private var banknote1StateHex = ""
    private var banknote2StateHex = ""
    private var cashProportionHex = ""
    private var cashCountryHex = ""

    private var channel1ParamHex = ""
    private var channel2ParamHex = ""
    private var channel3ParamHex = ""
    private var channel4ParamHex = ""
    private var channel5ParamHex = ""
    private var channel6ParamHex = ""
    private var channel7ParamHex = ""
    private var channel8ParamHex = ""
    private var channel9ParamHex = ""
    private var channel10ParamHex = ""

    private var motorForwardHex = ""
    private var motorReverseHex = ""
    private var motorStopDelayHex = ""

    companion object {
        fun getInstance(): ConfigFragment = ConfigFragment()
    }

    override fun createPresenter(): PackageManageContract.Presenter = PackageManagePresenter(lifecycleScope)

    override fun attachLayoutRes(): Int = R.layout.fragment_config

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        openEventBus = true
        isCountDownBackHome = false
    }

    override fun initView(view: View) {
        super.initView(view)

//        binding.spMotorMode.setSelection(basicConfigHex.substring(0, 2).toInt(16))
        binding.spMotorMode.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                logFile("出币模式选择：$position")
                motorModeHex = ByteUtil.int2HexStr(position, 2, false)?:"00"
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }

        binding.spMotor1State.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                logFile("选择马达1状态：$position")
                motor1StateModeHex = ByteUtil.int2HexStr(position, 2, false)?:"00"
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }

        binding.spMotor2State.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                logFile("选择马达2状态：$position")
                motor2StateModeHex = ByteUtil.int2HexStr(position, 2, false)?:"00"
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }

        binding.spDispenser1State.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                logFile("选择投币器1状态：$position")
                dispenser1StateHex = ByteUtil.int2HexStr(position, 2, false)?:"00"
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }

        binding.spCashCountry.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                logFile("选择纸钞国家：${position + 1}")
                cashCountryHex = ByteUtil.int2HexStr(position + 1, 2, false)?:"01"
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }

        binding.swDispenser2.setOnCheckedChangeListener { buttonView, isChecked ->
            logFile("选择投币器2状态：${if (isChecked) "打开" else "关闭"}")
            dispenser2StateHex = if (isChecked) "01" else "00"
        }

        binding.swBanknote1.setOnCheckedChangeListener { buttonView, isChecked ->
            logFile("选择纸钞机1状态：${if (isChecked) "打开" else "关闭"}")
            banknote1StateHex = if (isChecked) "01" else "00"
        }

        binding.swBanknote2.setOnCheckedChangeListener { buttonView, isChecked ->
            logFile("选择纸钞机2状态：${if (isChecked) "打开" else "关闭"}")
            banknote2StateHex = if (isChecked) "01" else "00"
        }

//        binding.etDispenser1Proportion.addTextChangedListener(object :TextWatcher{
//            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
//
//            }
//
//            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//                s?.let {
//                    val result = it.toString()
//                    if (result.isNotEmpty()){
//                        val p = result.toInt()
//                        if (p in 1..500){
//                            dispenser1ProportionHex = ByteUtil.int2HexStr(p, 4, true)?: "0001"
//                        }
//                    }
//                }
//            }
//
//            override fun afterTextChanged(s: Editable?) {
//
//            }
//        })
        setEditChange(binding.etDispenser1Proportion) { text ->
//            if (text.isNotEmpty()) {
//                val p = text.toInt()
//                if (p in 1..500) {
//                    dispenser1ProportionHex = ByteUtil.int2HexStr(p, 4, true) ?: "0001"
//                }
//            }
            dispenser1ProportionHex = verifyAfterText(text, 1, 500, 4, true, "0001")
        }
        setEditChange(binding.etDispenser2Proportion) { text ->
            dispenser2ProportionHex = verifyAfterText(text, 1, 500, 4, true, "0001")
        }
        setEditChange(binding.etCashProportion) { text ->
            cashProportionHex = verifyAfterText(text, 1, 500, 4, true, "0001")
        }

        setEditChange(binding.etChannel1) { text ->
            channel1ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel2) { text ->
            channel2ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel3) { text ->
            channel3ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel4) { text ->
            channel4ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel5) { text ->
            channel5ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel6) { text ->
            channel6ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel7) { text ->
            channel7ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel8) { text ->
            channel8ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel9) { text ->
            channel9ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etChannel10) { text ->
            channel10ParamHex = verifyAfterText(text, 0, 65000, 4, true, "0000")
        }
        setEditChange(binding.etMotorForward) { text ->
            motorForwardHex = verifyAfterText(text, 1, 8, 2, true, "04")
        }
        setEditChange(binding.etMotorReverse) { text ->
            motorReverseHex = verifyAfterText(text, 1, 4, 2, true, "02")
        }
        setEditChange(binding.etMotorStopDelay) { text ->
            motorStopDelayHex = verifyAfterText(text, 0, 80, 2, true, "14")
        }

        binding.btnBasicRefresh.onClick {
            refreshBasicConfig()
        }
        binding.btnBasicSave.onClick {
            saveBasicConfig()
        }

        binding.btnCashRefresh.onClick {
            refreshCashConfig()
        }
        binding.btnCashSave.onClick {
            saveCashConfig()
        }
        binding.btnMotorRefresh.onClick {
            refreshMotorConfig()
        }
        binding.btnMotorSave.onClick {
            saveMotorConfig()
        }

        binding.rlTouch.setTouchListener(object : TouchLinearLayout.TouchListener {
            override fun touch() {
                startCountDown()
            }
        })

        loadLocalData()
    }

    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
    ): FragmentConfigBinding {
        return FragmentConfigBinding.inflate(inflater, container, false)
    }

    override fun lazyLoad() {
        refreshBasicConfig()
        refreshCashConfig()
        refreshMotorConfig()
    }

    override fun onResume() {
        super.onResume()
        logFile("${javaClass.simpleName} onResume")
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (hidden) {
            logFile("${javaClass.simpleName}隐藏")
        } else {
            logFile("${javaClass.simpleName}显示")
        }
    }


    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    /**
     * 设置editext文本改变监听
     */
    private fun setEditChange(editText: EditText, textChange:(afterText: String) -> Unit){
        try {
            editText.addTextChangedListener(object : TextWatcher{
                override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

                }

                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                    s?.let {
                        val result = it.toString()
                        textChange(result)
                    }
                }

                override fun afterTextChanged(s: Editable?) {

                }
            })
        }catch (e: Exception){
            e.printStackTrace()
            logFile("设置editext文本改变监听异常：${e.message}")
        }
    }

    /**
     * 校验编辑框数据
     * @param text 变更后的文本
     * @param rangeMin 最小值
     * @param rangeMax 最大值
     * @param len 转16进制String后的长度
     * @param isLowFirst 是否低位在前
     * @param saveData 转换数据错误时返回的默认数据
     */
    private fun verifyAfterText(text: String, rangeMin: Long, rangeMax: Long, len: Int, isLowFirst: Boolean, saveData: String): String{
        return try {
            if (text.isNotEmpty()) {
                val p = text.toInt()
                when {
                    p in rangeMin..rangeMax -> ByteUtil.int2HexStr(p, len, isLowFirst)?: saveData
                    p > rangeMax -> {
                        showToastMsg("${requireContext().getString(R.string.value_over)}$rangeMin-$rangeMax")
                        ByteUtil.long2HexStr(rangeMax, len, isLowFirst)
                    }
                    p < rangeMin -> {
                        showToastMsg("${requireContext().getString(R.string.value_over)}$rangeMin-$rangeMax")
                        ByteUtil.long2HexStr(rangeMin, len, isLowFirst)
                    }
                    else -> {
                        ByteUtil.long2HexStr(0, len, isLowFirst)
                    }
                }
            }else{
                ""
            }
        }catch (e: Exception){
            e.printStackTrace()
            logFile("校验编辑框数据异常：${e.message}")
            saveData
        }
    }

    /**
     * 刷新基础配置
     */
    private fun refreshBasicConfig(){
        EventBus.getDefault().post(RefreshBasicConfigEvent(1))
    }

    /**
     * 保存基础配置
     */
    private fun saveBasicConfig(){
        if (motorModeHex.isEmpty()){
            return
        }
        if (motor1StateModeHex.isEmpty()){
            return
        }
        if (motor2StateModeHex.isEmpty()){
            return
        }
        if (dispenser1StateHex.isEmpty()){
            return
        }
        if (dispenser2StateHex.isEmpty()){
            return
        }
        if (dispenser1ProportionHex.isEmpty()){
            return
        }
        if (dispenser2ProportionHex.isEmpty()){
            return
        }
        if (banknote1StateHex.isEmpty()){
            return
        }
        if (banknote2StateHex.isEmpty()){
            return
        }
        if (cashProportionHex.isEmpty()){
            return
        }
        if (cashCountryHex.isEmpty()){
            return
        }
        val dataHex = "$motorModeHex$motor1StateModeHex$motor2StateModeHex$dispenser1StateHex$dispenser1ProportionHex$dispenser2StateHex$dispenser2ProportionHex$banknote1StateHex$banknote2StateHex$cashProportionHex$cashCountryHex"
        basicConfigHex = dataHex
        EventBus.getDefault().post(SaveBasicConfigEvent(dataHex))
        if (country != cashCountryHex.toInt(16)){
            country = cashCountryHex.toInt(16)
            if (switchLanguage(CommonUtil.getLanguage(cashCountryHex.toInt(16)))){
                showToastMsg(requireContext().getString(R.string.save_success_reboot))
            }else{
                logFile("切换语言失败")
            }
        }
    }

    /**
     * 刷新纸钞配置
     */
    private fun refreshCashConfig(){
        EventBus.getDefault().post(RefreshCashConfigEvent(1))
    }

    /**
     * 保存纸钞配置
     */
    private fun saveCashConfig(){
        if (channel1ParamHex.isEmpty()){
            return
        }
        if (channel2ParamHex.isEmpty()){
            return
        }
        if (channel3ParamHex.isEmpty()){
            return
        }
        if (channel4ParamHex.isEmpty()){
            return
        }
        if (channel5ParamHex.isEmpty()){
            return
        }
        if (channel6ParamHex.isEmpty()){
            return
        }
        if (channel7ParamHex.isEmpty()){
            return
        }
        if (channel8ParamHex.isEmpty()){
            return
        }
        if (channel9ParamHex.isEmpty()){
            return
        }
        if (channel10ParamHex.isEmpty()){
            return
        }
        val dataHex = "$channel1ParamHex$channel2ParamHex$channel3ParamHex$channel4ParamHex$channel5ParamHex$channel6ParamHex$channel7ParamHex$channel8ParamHex$channel9ParamHex$channel10ParamHex"
        cashConfigHex = dataHex
        EventBus.getDefault().post(SaveCashConfigEvent(dataHex))
    }

    /**
     * 刷新马达配置
     */
    private fun refreshMotorConfig(){
        EventBus.getDefault().post(RefreshMotorConfigEvent(1))
    }

    /**
     * 保存马达配置
     */
    private fun saveMotorConfig(){
        if (motorForwardHex.isEmpty()){
            return
        }
        if (motorReverseHex.isEmpty()){
            return
        }
        if (motorStopDelayHex.isEmpty()){
            return
        }

        val dataHex = "$motorForwardHex$motorReverseHex$motorStopDelayHex"
        motorConfigHex = dataHex
        EventBus.getDefault().post(SaveMotorConfigEvent(dataHex))
    }

    /**
     * 配置数据
     */
    private fun loadLocalData() {
        try {
            loadBasicConfig(basicConfigHex)
            loadCashConfig(cashConfigHex)
            loadMotorConfig(motorConfigHex)
        } catch (e: Exception) {
            e.printStackTrace()
            logFile("加载数据异常：" + e.message)
        }
    }

    /**
     * 加载基础数据 lyy模板配置格式
     */
    @SuppressLint("SetTextI18n")
    private fun loadBasicConfig(basicConfigHex: String){
        try {
            logFile("加载基础数据：$basicConfigHex")
            //00 00 00 00 0100 00 0100 00 00 0100 01
            motorModeHex = basicConfigHex.substring(0, 2)
            motor1StateModeHex = basicConfigHex.substring(2, 4)
            motor2StateModeHex = basicConfigHex.substring(4, 6)
            dispenser1StateHex = basicConfigHex.substring(6, 8)
            dispenser1ProportionHex = basicConfigHex.substring(8, 12)
            dispenser2StateHex = basicConfigHex.substring(12, 14)
            dispenser2ProportionHex = basicConfigHex.substring(14, 18)
            banknote1StateHex = basicConfigHex.substring(18, 20)
            banknote2StateHex = basicConfigHex.substring(20, 22)
            cashProportionHex = basicConfigHex.substring(22, 26)
            cashCountryHex = basicConfigHex.substring(26, 28)

            lifecycleScope.launch(Dispatchers.Main) {
                binding.spMotorMode.setSelection(motorModeHex.toInt(16))
                binding.spMotor1State.setSelection(motor1StateModeHex.toInt(16))
                binding.spMotor2State.setSelection(motor2StateModeHex.toInt(16))
                binding.spDispenser1State.setSelection(dispenser1StateHex.toInt(16))
                binding.etDispenser1Proportion.setText("${dispenser1ProportionHex.substring(2, 4)}${dispenser1ProportionHex.substring(0, 2)}".toLong(16).toString())
                binding.swDispenser2.isChecked = dispenser2StateHex == "01"
                binding.etDispenser2Proportion.setText("${dispenser2ProportionHex.substring(2, 4)}${dispenser2ProportionHex.substring(0, 2)}".toLong(16).toString())
                binding.swBanknote1.isChecked = banknote1StateHex == "01"
                binding.swBanknote2.isChecked = banknote2StateHex == "01"
                binding.etCashProportion.setText("${cashProportionHex.substring(2, 4)}${cashProportionHex.substring(0, 2)}".toLong(16).toString())
                binding.spCashCountry.setSelection(cashCountryHex.toInt(16) - 1)
            }
        } catch (e: Exception) {
            e.printStackTrace()
            logFile("加载基础数据异常：" + e.message)
        }
    }

    /**
     * 加载现金数据
     */
    @SuppressLint("SetTextI18n")
    private fun loadCashConfig(cashConfigHex: String){
        try {
            channel1ParamHex = cashConfigHex.substring(0, 4)
            channel2ParamHex = cashConfigHex.substring(4, 8)
            channel3ParamHex = cashConfigHex.substring(8, 12)
            channel4ParamHex = cashConfigHex.substring(12, 16)
            channel5ParamHex = cashConfigHex.substring(16, 20)
            channel6ParamHex = cashConfigHex.substring(20, 24)
            channel7ParamHex = cashConfigHex.substring(24, 28)
            channel8ParamHex = cashConfigHex.substring(28, 32)
            channel9ParamHex = cashConfigHex.substring(32, 36)
            channel10ParamHex = cashConfigHex.substring(36, 40)

            lifecycleScope.launch(Dispatchers.Main) {
                binding.etChannel1.setText("${channel1ParamHex.substring(2, 4)}${channel1ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel2.setText("${channel2ParamHex.substring(2, 4)}${channel2ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel3.setText("${channel3ParamHex.substring(2, 4)}${channel3ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel4.setText("${channel4ParamHex.substring(2, 4)}${channel4ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel5.setText("${channel5ParamHex.substring(2, 4)}${channel5ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel6.setText("${channel6ParamHex.substring(2, 4)}${channel6ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel7.setText("${channel7ParamHex.substring(2, 4)}${channel7ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel8.setText("${channel8ParamHex.substring(2, 4)}${channel8ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel9.setText("${channel9ParamHex.substring(2, 4)}${channel9ParamHex.substring(0, 2)}".toLong(16).toString())
                binding.etChannel10.setText("${channel10ParamHex.substring(2, 4)}${channel10ParamHex.substring(0, 2)}".toLong(16).toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
            logFile("加载现金数据异常：" + e.message)
        }
    }

    /**
     * 加载马达数据
     */
    @SuppressLint("SetTextI18n")
    private fun loadMotorConfig(motorConfigHex: String){
        try {
            motorForwardHex = motorConfigHex.substring(0, 2)
            motorReverseHex = motorConfigHex.substring(2, 4)
            motorStopDelayHex = motorConfigHex.substring(4, 6)

            lifecycleScope.launch(Dispatchers.Main) {
                binding.etMotorForward.setText(motorForwardHex.toLong(16).toString())
                binding.etMotorReverse.setText(motorReverseHex.toLong(16).toString())
                binding.etMotorStopDelay.setText(motorStopDelayHex.toLong(16).toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
            logFile("加载马达数据异常：" + e.message)
        }
    }

    private fun switchLanguage(languageParam: String): Boolean {
        logFile("languageParam=$languageParam")
        if (languageParam.isEmpty()) return false
        val lan = languageParam.split(",")[0]
        val area = languageParam.split(",")[1]
        Languages.entries.forEach { lanItem ->
            if (lanItem.lan == lan && lanItem.area == area) {
                language = lanItem
                return MultiLanguageUtils.changeLanguage(requireContext(), lan, "r$area")
            }
        }
        return false
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun recBasicConfigEvent(event: RecBasicConfigEvent) {
        logFile("刷新基础配置事件：${GsonUtil.getInstance()!!.toJson(event)}")
        loadBasicConfig(event.configHex)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun recCashConfigEvent(event: RecCashConfigEvent) {
        logFile("刷新纸钞通道配置事件：${GsonUtil.getInstance()!!.toJson(event)}")
        loadCashConfig(event.configHex)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun recMotorConfigEvent(event: RecMotorConfigEvent) {
        logFile("刷新马达配置事件：${GsonUtil.getInstance()!!.toJson(event)}")
        loadMotorConfig(event.configHex)
    }

}